package com.woniuxy.microsysserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.bean.current.PageInfos;
import com.woniuxy.microsysserver.entity.SlideShow;
import com.woniuxy.microsysserver.entity.SlideShowQuery;
import com.woniuxy.microsysserver.service.SlideShowService;
import com.woniuxy.microsysserver.uitl.Constant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @author: masterhai
 * @date: 2021/2/20:16:43
 * @description:轮播图控制器
 */
@RefreshScope
@Api(tags = "新闻测试相关接口")
@RestController
@RequestMapping(value = "/sys/slideshow",produces = MediaType.APPLICATION_JSON_VALUE)
public class SlideShowController {
    @Autowired
    private SlideShowService slideShowService;

    @ApiOperation("根据id查询轮播图")
    @GetMapping("/selectOne")
    public ResultBean selectOneSlideShow (int id) {
        SlideShow slideShow = slideShowService.selectOne(id);
        return ResultBean.builder().code(200).msg(Constant.SUCCESSFUL).data(slideShow).build();
    }



    @ApiOperation("查询新闻")
    @GetMapping("/selectAll")
    public ResultBean pageListUser (
            @ApiParam(name = "page", value = "当前页码", required = true)
             Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
             Integer limit,
            @ApiParam(name = "limit", value = "模糊查询名字", required = true)
            String name,
            @ApiParam(name = "status", value = "状态", required = true)
            Integer status) {
        PageInfo<SlideShow> pageInfo =  slideShowService.selectAll(page,limit,name,status);
        return ResultBean.builder().code(200).msg(Constant.SUCCESSFUL).data(pageInfo).build();
    }

    @ApiOperation("删除新闻")
    @PostMapping("/removeOrDelete")
    public ResultBean removeOrDelete(@RequestBody SlideShowQuery slideShowQuery){

        int i = slideShowService.removeOrDelete(slideShowQuery);

        return ResultBean.builder().code(200).msg(Constant.SUCCESSFUL).build();
    }





    @ApiOperation("添加新闻")
    @PostMapping("/addSlideShow")
    public ResultBean addSlideShow (@RequestBody SlideShow slideShow) {

       int i = slideShowService.addOneSlideShow(slideShow);

        if (i<0){
            return ResultBean.builder().code(605).msg(Constant.WRONG).build();

        }
        return ResultBean.builder().code(200).msg(Constant.SUCCESSFUL).build();

    }

    @ApiOperation("修改轮播图")
    @PostMapping("/updateOne")
    public ResultBean updateSlideShow (@RequestBody SlideShow slideShow) {
        int i = slideShowService.updateSlideShow(slideShow);
        return ResultBean.builder().code(200).msg(Constant.SUCCESSFUL).build();
    }
}
